#pragma once
#include "GameSystem.hpp"
#include "Light.hpp"
#include "GameObject.hpp"
#include "Box.hpp"
#include "Transform.hpp"
#include <set>
#include <vector>

namespace Typhoon {
	class LightSystem : public GameSystem
	{
	public:
		LightSystem();
		~LightSystem();

		void Render(GameObject* camera, const Box& viewport);
				
	protected:

		void GameObjectAdded(GameObject* gameObject);
		void GameObjectRemoved(GameObject* gameObject);

	private:

		struct Visualizer {
			Box BoundingBox;
		};

		Box viewport;
		GameObject* camera;

		void TransformChanged(DirtyProperty<Transform*, Matrix4x4>* dirtyProperty);

		void GridInsertion(Transform* transform);

		void CheckVisiblity(Transform* transform);
				
		typedef std::vector<Light*> VisibleLights;
		VisibleLights visibleLights;

		typedef std::set<Transform*> VisibilityChecks;
		VisibilityChecks visibilityChecks;

		typedef std::set<Transform*> InsertionChecks;
		InsertionChecks insertionChecks;
						
		void RenderLight(Light* light);

		const static int MaxLights = 8;

	};
}
